package com.wholesale.utils;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.wholesale.R;
import com.wholesale.beans.GoodsCategory;

public class Categories2ListAdapter extends ArrayAdapter<GoodsCategory>{

	//ListView中的数据来源
	private ListView listView;
	public Categories2ListAdapter(Context context, ListView listView) {
		super(context, 0);
		this.listView = listView ;
	}
	public Categories2ListAdapter(Context context,List<GoodsCategory> catInfoList, ListView listView) {
		super(context, 0,catInfoList);
		this.listView = listView ;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		Activity activity = (Activity) getContext();

        // Inflate the views from XML
        View rowView = convertView;
        Categories2Cache viewCache;
        if (rowView == null) {
            LayoutInflater inflater = activity.getLayoutInflater();
            rowView = inflater.inflate(R.layout.productitem, null);
            viewCache = new Categories2Cache(rowView);
            rowView.setTag(viewCache);
        } else {
            viewCache = (Categories2Cache) rowView.getTag();
        }
        GoodsCategory catInfo = getItem(position);
        // Set the text on the TextView
        TextView textView = viewCache.getTextView();
        textView.setText(catInfo.getCatName());
        return rowView;
	}
	/**
	 * 批量添加数据
	 * @param items
	 */
	public void addItems(List<GoodsCategory> items){
		for(GoodsCategory goodsCategory : items){
			this.add(goodsCategory);
		}
	}

}
